<?php

namespace App\Admin\Controllers;

use Illuminate\Http\Request;
use \App\Post;
class PostController extends Controller
{
	//首页
    public function index()
    {
    	$posts = Post::withoutGlobalScopes(['avaiable'])->where('status',0)->orderBy('created_at','desc')->paginate(10);
        return view('/admin/post/index',compact('posts'));
    }
    //状态
    public function status(Post $post)
    {
    	//验证
    	$this->validate(request(),[
    		'status' => 'required|in:1,-1',
    	]);
    	//逻辑
    	$post->status = request('status');
    	$post->save();
    	//渲染
        return ['error'=>0,'msg'=>''];
    }

}
